<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .top {
      width: 80%;
      height: 200px;
      background-color: pink;
    }

    .banner {
      width: 80%;
      height: 400px;
      background-color: aquamarine;
    }

    .main {
      width: 80%;
      height: 800px;
      background-color: red;
    }

    .foot {
      width: 80%;
      height: 400px;
      background-color: blanchedalmond;
    }

    .lan {
      position: absolute;
      right: 10%;
      top: 400px;
      width: 80px;
      height: 80px;
      background-color: cadetblue;
    }
  </style>
</head>

<body>
  <div class="top">头部区域</div>
  <div class="banner">banner区域</div>
  <div class="main">头部区域</div>
  <div class="foot">尾部区域</div>
  <div class="lan"></div>
  <script>
    var lan = document.querySelector(".lan");
    document.addEventListener("scroll", function () {
      // 147莽荒集
      var top = window.pageYOffset;
      if (top > 200) {
        // 改为固定定位。
        var topp = 400 - 200 + top;
        lan.style.top = topp + "px";
        if (top > 600) {
          lan.innerHTML = "返回顶部";
        } else {
          lan.innerHTML = "";
        }

      } else {
        lan.style.top = 400 + "px";
      }
    })
  </script>
</body>

</html>